package com.ddpt.platform.common.util.excel;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 读取excel监听器
 */
public class ReadExcelMapListener extends AbstractReadExcelListener<Map<String,String>,Map<Integer,String>> {

    private ReadExcelMapListener(){}

    public static ReadExcelMapListener builder(Integer maxReadCount, ExcelReaderCallBack<Map<String, String>> callBack){
        ReadExcelMapListener listener = new ReadExcelMapListener();
        if(maxReadCount!=null && maxReadCount>0){
            listener.maxReadCount = maxReadCount;
        }
        if(callBack != null){
            listener.callBack = callBack;
        }
        return listener;
    }

    public static ReadExcelMapListener builder(Integer maxReadCount, Set<Integer> skipRow, ExcelReaderCallBack<Map<String, String>> callBack){
        ReadExcelMapListener listener = new ReadExcelMapListener();
        if(maxReadCount!=null && maxReadCount>0){
            listener.maxReadCount = maxReadCount;
        }
        if(callBack != null){
            listener.callBack = callBack;
        }
        if (skipRow != null){
            listener.setSkipRow(skipRow);
        }
        return listener;
    }

    @Override
    protected Map<String, String> parse(Map<Integer, String> integerStringMap) {
        if(integerStringMap==null || integerStringMap.isEmpty()){
            return null;
        }
        Map<String, String> result = new HashMap<>();
        integerStringMap.forEach((k,v) -> {
            result.put(this.headers.get(k),v);
        });
        return result;
    }
}
